package org.learn.java;

public class Kary {

	private static String data = "0123456789ABCDEFGHIJK";

	public static void conversionToBase(int n, int base) {

		int v = 1;
		while (v <= n / base)
			v *= base;

		while (v > 0) {
			if (n >= v) {
				System.out.print(data.charAt(n / v));
				n = n % v;
			} else {
				System.out.print("0");
			}

			v /= base;
		}
		System.out.println();

	}

	public static void conversionToDecimal(String n, int base) {
		int len = n.length();
		int sum = 0;
		for (int i = 0; i < len; i++) {
			sum *= base;
			sum += data.indexOf(n.charAt(i));
		}
		
		System.out.println(sum);
	}
}